nexus\api\rtapi/
world.rs

1use super::RealTimeData;
2use num_enum::{IntoPrimitive, TryFromPrimitive};
3use std::net::Ipv4Addr;
4
5#[derive(Debug, Copy, Clone)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize))]
7pub struct WorldData {
8    /// Tyrian time of day.
9    pub time_of_day: Result<TimeOfDay, u32>,
10
11    /// Map id of current map.
12    pub map_id: u32,
13
14    /// Map type of current map.
15    pub map_type: Result<MapType, u32>,
16
17    /// IP address of current server.
18    pub ip_address: Ipv4Addr,
19
20    /// Location of cursor in the game world as ingame coordinates.
21    pub cursor: [f32; 3],
22}
23
24impl WorldData {
25    /// Reads world data from the given data pointer.
26    ///
27    /// # Safety
28    /// The pointer must be safe to read from.
29    pub unsafe fn read(data: *const RealTimeData) -> Self {
30        unsafe {
31            Self {
32                time_of_day: (*data).time_of_day.try_into(),
33                map_id: (*data).map_id,
34                map_type: (*data).map_type.try_into(),
35                ip_address: (*data).ip_address.into(),
36                cursor: (*data).cursor,
37            }
38        }
39    }
40}
41
42#[derive(
43    Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TryFromPrimitive, IntoPrimitive,
44)]
45#[num_enum(error_type(name = u32, constructor = From::from))]
46#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
47#[cfg_attr(
48    feature = "strum",
49    derive(
50        strum::AsRefStr,
51        strum::Display,
52        strum::EnumCount,
53        strum::EnumIter,
54        strum::IntoStaticStr,
55        strum::VariantArray,
56        strum::VariantNames
57    )
58)]
59#[repr(u32)]
60pub enum TimeOfDay {
61    Dawn,
62    Day,
63    Dusk,
64    Night,
65}
66
67#[derive(
68    Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TryFromPrimitive, IntoPrimitive,
69)]
70#[num_enum(error_type(name = u32, constructor = From::from))]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72#[cfg_attr(
73    feature = "strum",
74    derive(
75        strum::AsRefStr,
76        strum::Display,
77        strum::EnumCount,
78        strum::EnumIter,
79        strum::IntoStaticStr,
80        strum::VariantArray,
81        strum::VariantNames
82    )
83)]
84#[repr(u32)]
85pub enum MapType {
86    AutoRedirect,
87    CharacterCreation,
88    PvP,
89    GvG,
90    Instance,
91    Public,
92    Tournament,
93    Tutorial,
94    UserTournament,
95    WvWEternalBattlegrounds,
96    WvWBlueBorderlands,
97    WvWGreenBorderlands,
98    WvWRedBorderlands,
99    WVWFortunesVale,
100    WvWObsidianSanctum,
101    WvWEdgeOfTheMists,
102    PublicMini,
103    BigBattle,
104    WvWLounge,
105}